#if defined(ORATR_USE_HTTP)
#ifndef _HTTP_DOWNLOAD_H_INCLUDED_
#define _HTTP_DOWNLOAD_H_INCLUDED_

#include "win_tcpsocket.h"
#include <string>
using std::string;

#define GET_REQUEST_FORMAT		"GET %s HTTP/1.0\r\n\r\n"
#define HTTP_END_HEADER_STRING	"\r\n\r\n"

#define HTTP_OK_STRING					"200 OK"
#define HTTP_OK					200

#define HTTPERR_REQUEST			0x0001
#define HTTPERR_RESPONSE		0x0002
#define HTTPERR_NOTOK			0x0004
#define HTTPERR_HEADERSKIP		0x0008
#define HTTPERR_FILEIO			0x0010
#define HTTPERR_MEMORY			0x0020
#define HTTPERR_DISCONNECTED	0x0040

#define HttpErrorString( x, y ) itoa( y, x, sizeof( x ) )

typedef enum _tagHttpVersion
{
	HTTPVER_10 = 0x0100,
	HTTPVER_11 = 0x0101

}HttpVersion;

class CHttpDownload : public CWinTcpSocket
{
public:
	CHttpDownload( void );

	virtual int DownloadFile( const char *pszRemoteFile, const char *pszLocalFile );
	virtual int DownloadArray( const char *pszRemoteFile, string& data );

protected:
	bool MakeRequest( const char *pszRequest );
	int GetResponse( char *pszBuf );
	bool IsResponseOK( const char *pszResponse );
	int SkipHeader( void );
	int WriteToFile( const char *pszFile );
	int WriteToString( string &pszFile );
};

#endif
#endif
